﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace AnonsaiWPF.CSharp.TabControl
{
    /// <summary>
    /// Interaction logic for TabControlScrolling.xaml
    /// </summary>
    public partial class TabControlScrolling : Window, IWindow
    {
        public TabControlScrolling()
        {
            InitializeComponent();
        }

        public void DetachContent()
        {
            RemoveLogicalChild(Content);
        }

        private void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            VIBlend.WPF.Controls.TabItem item = this.TabControl.Items[this.TabControl.Items.Count - 1] as VIBlend.WPF.Controls.TabItem;
            if (item != null && item.IsSelected.HasValue && item.IsSelected.Value)
            {
                VIBlend.WPF.Controls.TabItem newItem = new VIBlend.WPF.Controls.TabItem("New TabItem");
                newItem.CloseButtonVisibility = System.Windows.Visibility.Visible;
                newItem.BackgroundOpacity = 0;
                newItem.Margin = new Thickness(5, 5, 0, 0);
                newItem.FontSize = 12;
                TabControl.Items.Insert(TabControl.Items.Count - 1, newItem);
                TabControl.SelectedIndex = TabControl.Items.Count - 2;
            }
        }

        private void checkBox1_Checked(object sender, RoutedEventArgs e)
        {
            if (this.TabControl == null)
                return;

            this.TabControl.SetCloseButtonVisibility(System.Windows.Visibility.Visible);
        }

        private void checkBox1_Unchecked(object sender, RoutedEventArgs e)
        {
            if (this.TabControl == null)
                return;

            this.TabControl.SetCloseButtonVisibility(System.Windows.Visibility.Collapsed);
        }

        public void SetTheme()
        {
        }

        public Grid Root
        {
            get
            {
                return this.RootVisual;
            }
        }
    }
}
